import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select

testCase = "DBshop010销售管理退货管理处理退货"
rootPath=get_pro_rootpath() #获取项目的绝对路径
filePath=rootPath+r'\public\order1.txt' #拼接文件路径
orderId=readFile(filePath) #读取文件内容
print(orderId)   #打印订单编号

firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,'销售管理','退货管理')
firefox.find_element_by_xpath("//input[@name='order_sn']").send_keys(orderId)
K = firefox.find_element_by_xpath("//select[@name='refund_type']")
ActionChains(firefox).move_to_element(K).perform()
Select(K).select_by_visible_text("退款到账户余额")
firefox.find_element_by_xpath("//button").click()
firefox.find_element_by_link_text("处理退货").click()
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys(2199)
firefox.find_element_by_id("re_refund_info").send_keys("同意")
firefox.find_element_by_xpath("//button").click()
time.sleep(3)
firefox = openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_xpath("//input[@placeholder='输入订单编号']").send_keys(orderId)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
try:
    firefox.find_element_by_xpath('//td[text()="退款成功"]/following-sibling::td/a' ).text
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()